*** If necessary, install the following packages:
// ssc install coefplot, replace
// ssc install estout, replace
// ssc install tabout, replace

log using CH_jop_appendix.log, text replace // log of appendix replication

set scheme plottig // set graphical scheme to plottig

********************************************************************************
*********************** Appendix A2 ********************************************
********************************************************************************

***** Figure A2
use "CH_pretest.dta", clear
gen race = 1 if group=="white-male"
	replace race = 2 if group=="black-male"
	replace race = 3 if group=="hispanic-male"
	replace race = 4 if group=="asian-male"
	replace race = 5 if group=="white-female"
	replace race = 6 if group=="black-female"
	replace race = 7 if group=="hispanic-female"
	replace race = 8 if group=="asian-female"
	

*** gen mean and sd for age
egen ageM = mean(age), by(race)
format ageM %9.1f
egen ageSD = sd(age), by(race)
gen age_lower = ageM-ageSD
gen age_upper = ageM+ageSD

twoway (rcap age_lower age_upper race, ///
		xlabel(1 `""White" "Men""' 2 `""Black" "Men""' ///
		3 `""Brown" "Men""'	4 `""Asian" "Men""' ///
		5 `""White" "Women""' 6 `""Black" "Women""' ///
		7 `""Brown" "Women""' 8 `""Asian" "Women""') ///
		xtitle("Race and Gender of Picture") ///
		ytitle("Mean Age (yrs)")) ///
	   (scatter ageM race, color(black) ///
	    mlabel(ageM) mlabcolor(black) mlabposition(1)), ///
	    legend(off) title("(a) Age" ) 
graph save "age.gph", replace 			

*** gen mean and sd for attract
egen attractM = mean(attract), by(race)
format attractM %9.1f
egen attractSD = sd(attract), by(race)
gen attract_lower = attractM-attractSD
gen attract_upper = attractM+attractSD

twoway (rcap attract_lower attract_upper race, ///
		xlabel(1 `""White" "Men""' 2 `""Black" "Men""' ///
		3 `""Brown" "Men""'	4 `""Asian" "Men""' ///
		5 `""White" "Women""' 6 `""Black" "Women""' ///
		7 `""Brown" "Women""' 8 `""Asian" "Women""') ///
		xtitle("Race and Gender of Picture") ///
		ytitle("Mean attract (yrs)")) ///
	   (scatter attractM race, color(black) ///
	    mlabel(attractM) mlabcolor(black) mlabposition(1)), ///
	    legend(off) title("(b) Attractiveness" ) 
graph save "attract.gph", replace 			

*** gen mean and sd for competence
egen compM = mean(comp), by(race)
format compM %9.1f
egen compSD = sd(comp), by(race)
gen comp_lower = compM-compSD
gen comp_upper = compM+compSD

twoway (rcap comp_lower comp_upper race, ///
		xlabel(1 `""White" "Men""' 2 `""Black" "Men""' ///
		3 `""Brown" "Men""'	4 `""Asian" "Men""' ///
		5 `""White" "Women""' 6 `""Black" "Women""' ///
		7 `""Brown" "Women""' 8 `""Asian" "Women""') ///
		xtitle("Race and Gender of Picture") ///
		ytitle("Mean comp (yrs)")) ///
	   (scatter compM race, color(black) ///
	    mlabel(compM) mlabcolor(black) mlabposition(1)), ///
	    legend(off) title("(c) Competence" ) 
graph save "comp.gph", replace 			
		
*** gen mean and sd for likeability
egen likeM = mean(like), by(race)
format likeM %9.1f
egen likeSD = sd(like), by(race)
gen like_lower = likeM-likeSD
gen like_upper = likeM+likeSD

twoway (rcap like_lower like_upper race, ///
		xlabel(1 `""White" "Men""' 2 `""Black" "Men""' ///
		3 `""Brown" "Men""'	4 `""Asian" "Men""' ///
		5 `""White" "Women""' 6 `""Black" "Women""' ///
		7 `""Brown" "Women""' 8 `""Asian" "Women""') ///
		xtitle("Race and Gender of Picture") ///
		ytitle("Mean like (yrs)")) ///
	   (scatter likeM race, color(black) ///
	    mlabel(likeM) mlabcolor(black) mlabposition(1)), ///
	    legend(off) title("(d) Likeability" ) 
graph save "like.gph", replace 		

// combine saved graphs into a single figure							
graph combine "age.gph" "attract.gph" "comp.gph" "like.gph", xcommon ycommon 	
		
********************************************************************************
*********************** Appendix A3 ********************************************
********************************************************************************

*** Table A1 Sample Statitics Characteristics
// Main Data
use "CH_main.dta", clear

tabout female race age party edu using "tableA1.csv", ptotal(none) ///
	   oneway cells(col) clab(2019) style(csv) format(2) replace
	
// 2021 Data
use "CH_followup.dta", clear

tabout female race age party edu using "tableA1.csv", ptotal(none) ///
	   oneway cells(col) clab(2021) style(csv) format(2) append


*** Table A2 Sample Treatment Balance
use "CH_main.dta", clear

// Tabout generates summary tables as .csv
tabout female panel using "tableA2.csv" if outcome==1, ptotal(none) ///
	cells(col) style(csv) format(2) h1(UNHCR Report Not Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) replace
tabout race panel using "tableA2.csv" if outcome==1, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Not Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout age panel using "tableA2.csv" if outcome==1, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Not Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout party panel using "tableA2.csv" if   outcome==1, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Not Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout female panel using "tableA2.csv" if   outcome==2, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout race panel using "tableA2.csv" if outcome==2, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout age panel using "tableA2.csv" if outcome==2, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout party panel using "tableA2.csv" if outcome==2, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append

*** Table A3 Sample Treatment Balance (w/o country labels)
// Use followup data
use "CH_followup.dta", clear

// Tabout generates summary tables as .csv
tabout female panel using "tableA3.csv" if country==1 & outcome==1, ptotal(none) ///
	cells(col) style(csv) format(2) h1(UNHCR Report Not Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) replace
tabout race panel using "tableA3.csv" if country==1 & outcome==1, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Not Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout age panel using "tableA3.csv" if country==1 & outcome==1, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Not Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout party panel using "tableA3.csv" if country==1 & outcome==1, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Not Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout female panel using "tableA3.csv" if country==1 & outcome==2, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout race panel using "tableA3.csv" if country==1 & outcome==2, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout age panel using "tableA3.csv" if country==1 & outcome==2, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout party panel using "tableA3.csv" if country==1 & outcome==2, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append

*** Table A4 Sample Treatment Balance (w/ country labels)
tabout female panel using "tableA4.csv" if country==2 & outcome==1, ptotal(none) ///
	cells(col) style(csv) format(2) h1(UNHCR Report Not Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) replace
tabout race panel using "tableA4.csv" if country==2 & outcome==1, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Not Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout age panel using "tableA4.csv" if country==2 & outcome==1, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Not Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout party panel using "tableA4.csv" if country==2 & outcome==1, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Not Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout female panel using "tableA4.csv" if country==2 & outcome==2, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout race panel using "tableA4.csv" if country==2 & outcome==2, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout age panel using "tableA4.csv" if country==2 & outcome==2, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append
tabout party panel using "tableA4.csv" if country==2 & outcome==2, ptotal(none) ///
	cells(col) style(csv) format(2)  h1(UNHCR Report Critical of U.S.) ///
	h2(| White-Male | Mixed-Male | White-Mixed | Mixed-Mixed) append

********************************************************************************
*********************** Appendix A4 ********************************************
********************************************************************************
use "CH_main.dta", clear

// recalculate factor and irt scales
factor imm1 imm2_1 imm2_2 imm3, pcf
		predict immigration
irt grm imm1 imm2_1 imm2_2 imm3
		predict immigration1
factor race1_1 race1_2 race1_3 race1_4 race1_6 race1_8 race2, pcf
		predict white_id
irt grm race1_1 race1_2 race1_3 race1_4 race1_6 race1_8 race2
		predict white_id1	

*** Figure A4: FA and IRT Construction of White Nationalism and Anti-Immigration 
hist immigration, percent scheme(plottig) color(538g) ///
	xtitle("Anti-Immigration Attitudes") title("(a) Factor Analysis") 
	graph save "imm_hist.gph", replace

hist white_id, percent scheme(plottig) color(538g) ///
	xtitle("White Nationalism") title("(c) Factor Analysis") 
	graph save "race_hist.gph", replace
	
hist immigration1, percent scheme(plottig) color(538g) ///
	xtitle("Anti-Immigration Attitudes") title("(b) Item Response Theory") 
	graph save "imm_hist1.gph", replace

hist white_id1, percent scheme(plottig) color(538g) ///
	xtitle("White Nationalism") title("(d) Item Response Theory") 
	graph save "race_hist1.gph", replace		   
	
graph combine "imm_hist.gph" "imm_hist1.gph" "race_hist.gph" "race_hist1.gph" 


*** Table A5: Trust and Fairness of the UNHCR Decision-Making Process
gen patriot = pat1+pat2+pat3
// setup short variable for all controls	
global controls inc age i.party i.white i.female c.edu ///
				immigration white_id patriot
				
// labeling variables
label var immigration "Anti-immigration"
label var white_id "White Nationalism"
label var female "Female"
label var inc "Household Income"
label var age "Age"
label var patriot "Patriotism"
label var edu "Education"
label var white "White"
					
probit fair_b i.panel $controls if outcome==1, robust
	estimates store m1
probit fair_b i.panel $controls if outcome==2, robust
	estimates store m2	
probit trust_b i.panel $controls if outcome==1, robust
	estimates store m3
probit trust_b i.panel $controls if outcome==2, robust
	estimates store m4	

esttab m1 m2 m3 m4 using "tableA5.csv", pr2 b(2) se(2) obslast ///
	   nobaselevels label replace nogaps ///
	   coeflabels(2.party2 "Democrats" 3.party2 "Republicans" ///
	   2.panel "Mixed-Males" 3.panel "White-Mixed" 4.panel "Mixed-Mixed") 

*** Table A6: UNHCR Report Outcome for Refugees and U.S. Citizens
probit refugee_b i.panel $controls if outcome==1, robust
	estimates store m5
probit refugee_b i.panel $controls if outcome==2, robust
	estimates store m6
probit american_b i.panel $controls if outcome==1, robust
	estimates store m7
probit american_b i.panel $controls if outcome==2, robust
	estimates store m8			
	
esttab m5 m6 m7 m8 using "tableA6.csv", pr2 b(2) se(2) obslast ///
	   nobaselevels label replace nogaps ///
	   coeflabels(2.party2 "Democrats" 3.party2 "Republicans" ///
	   2.panel "Mixed-Males" 3.panel "White-Mixed" 4.panel "Mixed-Mixed")

********************************************************************************
*********************** Appendix A5 ********************************************
********************************************************************************		

*** Table A7: Alternative Dependent Variable (Factor Analysis Construction)

factor fair trust refugee american, ipf factors(2)
predict substantive procedural 

reg procedural i.panel $controls if outcome==1, robust
	estimates store f1
reg procedural i.panel $controls if outcome==2, robust
	estimates store f2
reg substantive i.panel $controls if outcome==1, robust
	estimates store f3
reg substantive i.panel $controls if outcome==2, robust
	estimates store f4		
	
esttab f1 f2 f3 f4 using "tableA7.csv", r2 b(2) se(2) obslast ///
	   nobaselevels label replace nogaps ///
	   coeflabels(2.party2 "Democrats" 3.party2 "Republicans" ///
	   2.panel "Mixed-Males" 3.panel "White-Mixed" 4.panel "Mixed-Mixed")

*** Table A8: Descriptive Representation Effect on Substantive and Procedural Legitimacy

reg refugee i.panel $controls if outcome==1, robust
	estimates store m1
reg refugee i.panel $controls if outcome==2, robust
	estimates store m2
reg american i.panel $controls if outcome==1, robust
	estimates store m3
reg american i.panel $controls if outcome==2, robust
	estimates store m4	
reg fair i.panel $controls, robust
	estimates store m5
reg trust i.panel $controls, robust
	estimates store m6	
	
esttab m1 m2 m3 m4 m5 m6 using "tableA8.csv", r2 b(2) se(2) obslast ///
	   nobaselevels label replace nogaps ///
	   coeflabels(2.party2 "Democrats" 3.party2 "Republicans" ///
	   2.panel "Mixed-Males" 3.panel "White-Mixed" 4.panel "Mixed-Mixed")		

********************************************************************************
****************** Appendix A6 *************************************************
********************************************************************************
use "CH_main.dta", clear

*** Figure A5: UNHCR Panel Diversity and Legitimacy, by Media Attention

// Media Attention
reg fair i.panel##c.interest, robust
	margins r.panel if panel==1 | panel==4, over(interest) post
	estimates store m1
reg trust i.panel##c.interest, robust
	margins r.panel if panel==1 | panel==4, over(interest) post
	estimates store m2
reg american i.panel##c.interest, robust
	margins r.panel if panel==1 | panel==4, over(interest) post
	estimates store m3
reg refugee i.panel##c.interest, robust
	margins r.panel if panel==1 | panel==4, over(interest) post
	estimates store m4
	
coefplot m1, bylabel("UNHCR is Fair") || ///
		 m2, bylabel("UNHCR can be Trusted") || /// 
		 m3, bylabel("Outcome Good for Americans") || ///
		 m4, bylabel("Outcome Good for Refugees") format(%9.2g) ///
		 vertical scheme(plottig) ///
		 xlabel(1 "1" 2 "2" 3 "3" 4 "4" 5 "5") ///
		 yline(0) ciopts(recast(rcap)) title("Attention to National Politics") ///
		 xtitle("Attention to national politics") ///
		 ytitle("Marginal Difference" "(White-Male vs. Mixed-Mixed)") byopts(rows(1))
graph save "media1.gph", replace

// Media Consumption
reg fair i.panel##c.media, robust
	margins r.panel if panel==1 | panel==4, over(media1) post
	estimates store m5
reg trust i.panel##c.media, robust
	margins r.panel if panel==1 | panel==4, over(media1) post
	estimates store m6
reg american i.panel##c.media, robust
	margins r.panel if panel==1 | panel==4, over(media1) post
	estimates store m7
reg refugee i.panel##c.media, robust
	margins r.panel if panel==1 | panel==4, over(media1) post
	estimates store m8	

coefplot m5, bylabel("UNHCR is Fair") || ///
		 m6, bylabel("UNHCR can be Trusted") || /// 
		 m7, bylabel("Outcome Good for Americans") || ///
		 m8, bylabel("Outcome Good for Refugees") format(%9.2g) ///
		 vertical scheme(plottig) ///
		 xlabel(1 "0" 2 "1" 3 "2" 4 "3" 5 "4" 6 "5" 7 "6" 8 "7") ///
		 yline(0) ciopts(recast(rcap)) title("Political Media Consumption") ///
		 xtitle("Number of days following political news per week") ///
		 ytitle("Marginal Difference" "(White-Male vs. Mixed-Mixed)") byopts(rows(1))
graph save "media2.gph", replace	
	
graph combine "media1.gph" "media2.gph", ycommon rows(2)
	  
*** Figure A6: UNHCR Panel Diversity and Legitimacy, by Respondent Attentiveness
reg fair i.panel##i.attention, robust
	margins r.panel, at(attention=0) post
	estimates store fair0
reg fair i.panel##i.attention, robust
	margins r.panel, at(attention=1) post
	estimates store fair1	
reg trust i.panel##i.attention, robust
	margins r.panel, at(attention=0) post
	estimates store trust0
reg trust i.panel##i.attention, robust
	margins r.panel, at(attention=1) post
	estimates store trust1	
reg american i.panel##i.attention, robust
	margins r.panel, at(attention=0) post
	estimates store american0
reg american i.panel##i.attention, robust
	margins r.panel, at(attention=1) post
	estimates store american1	
reg refugee i.panel##i.attention, robust
	margins r.panel, at(attention=0) post
	estimates store refugee0	  
reg refugee i.panel##i.attention, robust
	margins r.panel, at(attention=1) post
	estimates store refugee1	
	
coefplot fair0 fair1, bylabel("UNHCR is Fair") || ///
		 trust0 trust1, bylabel("UNHCR can be Trusted") || /// 
		 american0 american1, bylabel("Outcome Good for Americans") || ///
		 refugee0 refugee1, bylabel("Outcome Good for Refugees") format(%9.2g) ///
		 vertical scheme(plottig) ///
		 yline(0) ciopts(recast(rcap)) ///
		 xlabel(1 `""Mixed-Race" "All-Male""' 2 `""All-White" "Mixed-Gender""' ///
			    3 `""Mixed-Race" "Mixed-Gender""') ///
		 xtitle("Racial and Gender Distribution of UNHCR Panel") ///
		 ytitle("Marginal Treatment Effect" "(All-White vs. Diverse Panels") ///
		 legend(order(2 "Low Attention" 4 "High Attention") rows(1))
		 
*** Figure A7: UNHCR Diversity and Procedural Legitimacy Replication Comparison
use "CH_main.dta", clear // 2019 Main Survey Sample

reg american i.panel if outcome==1, robust
	margins r.panel, vsquish post
	estimates store american1
reg american i.panel if outcome==2, robust
	margins r.panel, vsquish post
	estimates store american2	
reg refugee i.panel if outcome==1, robust
	margins r.panel, vsquish post
	estimates store refugee1
reg refugee i.panel if outcome==2, robust
	margins r.panel, vsquish post
	estimates store refugee2	
reg fair i.panel if outcome==1, robust
	margins r.panel, vsquish post
	estimates store fair1
reg fair i.panel if outcome==2, robust
	margins r.panel, vsquish post
	estimates store fair2	
reg trust i.panel if outcome==2, robust
	margins r.panel, vsquish post
	estimates store trust1	
reg trust i.panel if outcome==2, robust
	margins r.panel, vsquish post
	estimates store trust2		
	
use "CH_followup.dta", clear // 2021 Sample w/o country labels
	keep if country==1	

reg american i.panel if outcome==1, robust
	margins r.panel, vsquish post
	estimates store american3
reg american i.panel if outcome==2, robust
	margins r.panel, vsquish post
	estimates store american4	
reg refugee i.panel if outcome==1, robust
	margins r.panel, vsquish post
	estimates store refugee3
reg refugee i.panel if outcome==2, robust
	margins r.panel, vsquish post
	estimates store refugee4	
reg fair i.panel if outcome==1, robust
	margins r.panel, vsquish post
	estimates store fair3
reg fair i.panel if outcome==2, robust
	margins r.panel, vsquish post
	estimates store fair4	
reg trust i.panel if outcome==1, robust
	margins r.panel, vsquish post
	estimates store trust3	
reg trust i.panel if outcome==2, robust
	margins r.panel, vsquish post
	estimates store trust4	
	
use "CH_followup.dta", clear // 2021 Sample w/ country labels
	keep if country==2

reg american i.panel if outcome==1, robust
	margins r.panel, vsquish post
	estimates store american5
reg american i.panel if outcome==2, robust
	margins r.panel, vsquish post
	estimates store american6	
reg refugee i.panel if outcome==1, robust
	margins r.panel, vsquish post
	estimates store refugee5
reg refugee i.panel if outcome==2, robust
	margins r.panel, vsquish post
	estimates store refugee6	
reg fair i.panel if outcome==1, robust
	margins r.panel, vsquish post
	estimates store fair5
reg fair i.panel if outcome==2, robust
	margins r.panel, vsquish post
	estimates store fair6	
reg trust i.panel if outcome==1, robust
	margins r.panel, vsquish post
	estimates store trust5	
reg trust i.panel if outcome==2, robust
	margins r.panel, vsquish post
	estimates store trust6		
	
coefplot (fair1, color(538g) ciopts(lcolor(538g) recast(rcap))) ///
		 (fair3, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
		 (fair5, color(538r) ciopts(lcolor(538r) recast(rcap))), ///
		  bylabel("(a) UNHCR is Fair (Non-critical Report)") || ///
		 (fair2, color(538g) ciopts(lcolor(538g) recast(rcap))) ///
		 (fair4, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
		 (fair6, color(538r) ciopts(lcolor(538r) recast(rcap))), ///
		  bylabel("(b) UNHCR is Fair (Critical Report)") || ///
		 (trust1, color(538g) ciopts(lcolor(538g) recast(rcap))) ///
		 (trust3, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
		 (trust5, color(538r) ciopts(lcolor(538r) recast(rcap))), ///
		 bylabel("(c) UNHCR Can Be Trusted (Non-critical Report)") || ///
		 (trust2, color(538g) ciopts(lcolor(538g) recast(rcap))) ///
		 (trust4, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
		 (trust6, color(538r) ciopts(lcolor(538r) recast(rcap))), ///
		 bylabel("(d) UNHCR Can Be Trusted (Critical Report)")  ///
		 vertical ciopts(recast(rcap)) ///
		 ytitle("Marginal Difference (All-White, All-Male Panel vs. Diverse Panels)") ///
		 scheme(plottig) yline(0) ///
		 xtitle("Racial and Gender Distribution of Panel (All-White, All-Male as Reference Group)") ///
		 xlabel(1 `""Mixed-Race" "All-Male""' 2 `""All-White" "Mixed-Gender""' ///
				3 `""Mixed-Race" "Mixed-Gender""', labcol(black)) ///
		 legend(order(2 "2019 Sample" 4 "2021 Sample (No Country Labels)" ///
			    6 "2021 Sample (Country Labels)") rows(1))		  

* Figure A8: UNHCR Diversity and Substantive Legitimacy Replication Comparison 				
		 
coefplot (refugee1, color(538g) ciopts(lcolor(538g) recast(rcap))) ///
		 (refugee3, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
		 (refugee5, color(538r) ciopts(lcolor(538r) recast(rcap))), ///
		  bylabel("(a) Outcome Good for Refugees (Non-critical Report)") || ///
		 (refugee2, color(538g) ciopts(lcolor(538g) recast(rcap))) ///
		 (refugee4, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
		 (refugee6, color(538r) ciopts(lcolor(538r) recast(rcap))), ///
		  bylabel("(b) Outcome Good for Refugees (Critical Report)") || ///
		 (american1, color(538g) ciopts(lcolor(538g) recast(rcap))) ///
		 (american3, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
		 (american5, color(538r) ciopts(lcolor(538r) recast(rcap))), ///
		 bylabel("(c) Outcome Good for Americans (Non-critical Report)") || ///
		 (american2, color(538g) ciopts(lcolor(538g) recast(rcap))) ///
		 (american4, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
		 (american6, color(538r) ciopts(lcolor(538r) recast(rcap))), ///
		 bylabel("(d) Outcome Good for Americans (Critical Report)")  ///
		 vertical ciopts(recast(rcap)) ///
		 ytitle("Marginal Difference (All-White, All-Male Panel vs. Diverse Panels)") ///
		 scheme(plottig) yline(0) ///
		 xtitle("Racial and Gender Distribution of Panel (All-White, All-Male as Reference Group)") ///
		 xlabel(1 `""Mixed-Race" "All-Male""' 2 `""All-White" "Mixed-Gender""' ///
				3 `""Mixed-Race" "Mixed-Gender""', labcol(black)) ///
		 legend(order(2 "2019 Sample" 4 "2021 Sample (No Country Labels)" ///
			    6 "2021 Sample (Country Labels)") rows(1))	
	  
********************************************************************************
****************** Appendix A7 *************************************************
********************************************************************************  

*** Figure A9: UNHCR Panel Diversity and Procedural Legitimacy, by Political Attitudes
use "CH_main.dta", clear	
// recalculate factor and irt scales
factor imm1 imm2_1 imm2_2 imm3, pcf
		predict immigration
irt grm imm1 imm2_1 imm2_2 imm3
		predict immigration1
factor race1_1 race1_2 race1_3 race1_4 race1_6 race1_8 race2, pcf
		predict white_id
irt grm race1_1 race1_2 race1_3 race1_4 race1_6 race1_8 race2
		predict white_id1	

reg fair i.panel##c.white_id if outcome==1, robust		 
	margins r.panel if panel==1 | panel==4, at(white_id=(-1.5(.5)2)) post
	estimates store fair1
reg fair i.panel##c.white_id if outcome==2, robust		 
	margins r.panel if panel==1 | panel==4, at(white_id=(-1.5(.5)2)) post
	estimates store fair2	
reg trust i.panel##c.white_id if outcome==1, robust		 
	margins r.panel if panel==1 | panel==4, at(white_id=(-1.5(.5)2)) post
	estimates store trust1
reg trust i.panel##c.white_id if outcome==2, robust		 
	margins r.panel if panel==1 | panel==4, at(white_id=(-1.5(.5)2)) post
	estimates store trust2
reg fair i.panel##c.immigration if outcome==1, robust		 
	margins r.panel if panel==1 | panel==4, at(immigration=(-1.5(.5)2)) post
	estimates store fair3
reg fair i.panel##c.immigration if outcome==2, robust		 
	margins r.panel if panel==1 | panel==4, at(immigration=(-1.5(.5)2)) post
	estimates store fair4	
reg fair i.panel##c.immigration if outcome==1, robust		 
	margins r.panel if panel==1 | panel==4, at(immigration=(-1.5(.5)2)) post
	estimates store trust3
reg fair i.panel##c.immigration if outcome==2, robust		 
	margins r.panel if panel==1 | panel==4, at(immigration=(-1.5(.5)2)) post
	estimates store trust4		
	
coefplot fair1, bylabel("Non-critical Report of U.S.") || ///
		 fair2, bylabel("Critical Report of U.S.") ///
		 yline(0) scheme(plottig) vertical ciopts(recast(rcap)) ///
		 xtitle("White Nationalism") title("UNHCR is Fair") ///
		 xlabel(1 "-1.5" 2 "-1" 3 "-0.5" 4 "0" 5 "0.5" 6 "1" 7 "1.5" 8 "2") ///
		 ytitle("Marginal Effect") 		
		 graph save "wnat1.gph", replace

coefplot trust1, bylabel("Non-critical Report of U.S.") || ///
		 trust2, bylabel("Critical Report of U.S.") ///
		 yline(0) scheme(plottig) vertical ciopts(recast(rcap)) ///
		 xtitle("White Nationalism") title("UNHCR can be Trusted") ///
		 xlabel(1 "-1.5" 2 "-1" 3 "-0.5" 4 "0" 5 "0.5" 6 "1" 7 "1.5" 8 "2") ///
		 ytitle("Marginal Effect") 		
		 graph save "wnat2.gph", replace

graph combine "wnat1.gph" "wnat2.gph", ///
	  xcommon ycommon title("White Nationalism", size(med)) name(white1)
	  
coefplot fair3, bylabel("Non-critical Report of U.S.") || ///
		 fair4, bylabel("Critical Report of U.S.") ///
		 yline(0) scheme(plottig) vertical ciopts(recast(rcap)) ///
		 xtitle("Anti-Immigration Attitudes") title("UNHCR is Fair") ///
		 xlabel(1 "-1.5" 2 "-1" 3 "-0.5" 4 "0" 5 "0.5" 6 "1" 7 "1.5" 8 "2") ///
		 ytitle("Marginal Effect") 		
		 graph save "imm1.gph", replace

coefplot trust3, bylabel("Non-critical Report of U.S.") || ///
		 trust4, bylabel("Critical Report of U.S.") ///
		 yline(0) scheme(plottig) vertical ciopts(recast(rcap)) ///
		 xtitle("Anti-Immigration Attitudes") title("UNHCR can be Trusted") ///
		 xlabel(1 "-1.5" 2 "-1" 3 "-0.5" 4 "0" 5 "0.5" 6 "1" 7 "1.5" 8 "2") ///
		 ytitle("Marginal Effect") 		
		 graph save "imm2.gph", replace

graph combine "imm1.gph" "imm2.gph", ///
	  xcommon ycommon title("Anti-Immigration Attitudes", size(med)) name(imm1)		 

graph combine imm1 white1, rows(2) scale(1.4)	  
								
*** Figure A10: UNHCR Panel Diversity and Substantive Legitimacy, by Political 

reg refugee i.panel##c.white_id if outcome==1, robust		 
	margins r.panel if panel==1 | panel==4, at(white_id=(-1.5(.5)2)) post
	estimates store refugee1
reg refugee i.panel##c.white_id if outcome==2, robust		 
	margins r.panel if panel==1 | panel==4, at(white_id=(-1.5(.5)2)) post
	estimates store refugee2
reg american i.panel##c.white_id if outcome==1, robust		 
	margins r.panel if panel==1 | panel==4, at(white_id=(-1.5(.5)2)) post
	estimates store american1
reg american i.panel##c.white_id if outcome==2, robust		 
	margins r.panel if panel==1 | panel==4, at(white_id=(-1.5(.5)2)) post
	estimates store american2
reg refugee i.panel##c.immigration if outcome==1, robust		 
	margins r.panel if panel==1 | panel==4, at(immigration=(-1.5(.5)2)) post
	estimates store refugee3
reg refugee i.panel##c.immigration if outcome==2, robust		 
	margins r.panel if panel==1 | panel==4, at(immigration=(-1.5(.5)2)) post
	estimates store refugee4				
reg american i.panel##c.immigration if outcome==1, robust		 
	margins r.panel if panel==1 | panel==4, at(immigration=(-1.5(.5)2)) post
	estimates store american3
reg american i.panel##c.immigration if outcome==2, robust		 
	margins r.panel if panel==1 | panel==4, at(immigration=(-1.5(.5)2)) post
	estimates store american4	
				
coefplot refugee1, bylabel("Non-critical Report of U.S.") || ///
		 refugee2, bylabel("Critical Report of U.S.") ///
		 yline(0) scheme(plottig) vertical ciopts(recast(rcap)) ///
		 xtitle("White Nationalism") title("Outcome Good for Refugees") ///
		 xlabel(1 "-1.5" 2 "-1" 3 "-0.5" 4 "0" 5 "0.5" 6 "1" 7 "1.5" 8 "2") ///
		 ytitle("Marginal Effect") 		
		 graph save "wnat3.gph", replace

coefplot american1, bylabel("Non-critical Report of U.S.") || ///
		 american2, bylabel("Critical Report of U.S.") ///
		 yline(0) scheme(plottig) vertical ciopts(recast(rcap)) ///
		 xtitle("White Nationalism") title("Outcome Good for Americans") ///
		 xlabel(1 "-1.5" 2 "-1" 3 "-0.5" 4 "0" 5 "0.5" 6 "1" 7 "1.5" 8 "2") ///
		 ytitle("Marginal Effect") 		
		 graph save "wnat4.gph", replace

graph combine "wnat3.gph" "wnat4.gph", ///
	  xcommon ycommon title("White Nationalism", size(med)) name(white2)
	  
coefplot refugee3, bylabel("Non-critical Report of U.S.") || ///
		 refugee4, bylabel("Critical Report of U.S.") ///
		 yline(0) scheme(plottig) vertical ciopts(recast(rcap)) ///
		 xtitle("Anti-Immigration Attitudes") title("Outcome Good for Refugees") ///
		 xlabel(1 "-1.5" 2 "-1" 3 "-0.5" 4 "0" 5 "0.5" 6 "1" 7 "1.5" 8 "2") ///
		 ytitle("Marginal Effect") 		
		 graph save "imm3.gph", replace

coefplot american3, bylabel("Non-critical Report of U.S.") || ///
		 american4, bylabel("Critical Report of U.S.") ///
		 yline(0) scheme(plottig) vertical ciopts(recast(rcap)) ///
		 xtitle("Anti-Immigration Attitudes") title("Outcome Good for Americans") ///
		 xlabel(1 "-1.5" 2 "-1" 3 "-0.5" 4 "0" 5 "0.5" 6 "1" 7 "1.5" 8 "2") ///
		 ytitle("Marginal Effect") 		
		 graph save "imm4.gph", replace

graph combine "imm3.gph" "imm4.gph", ///
	  xcommon ycommon title("Anti-Immigration Attitudes", size(med)) name(imm2)		 

graph combine imm2 white2, rows(2) scale(1.4)	  
								
								
*** Figure A11: Conditional Marginal Treatment Effects of Diversity, by Partisanship (2021)
use "CH_followup.dta", clear

// american
reg american i.panel##i.party, robust
	margins r.panel, at(party=1) vsquish post
	estimates store ind1
reg american i.panel##i.party, robust
	margins r.panel, at(party=2) vsquish post
	estimates store dem1
reg american i.panel##i.party, robust
	margins r.panel, at(party=3) vsquish post
	estimates store rep1	
// refugee	
reg refugee i.panel##i.party, robust
	margins r.panel, at(party=1) vsquish post
	estimates store ind2
reg refugee i.panel##i.party##outcome, robust
	margins r.panel, at(party=2) vsquish post
	estimates store dem2
reg refugee i.panel##i.party##outcome, robust
	margins r.panel, at(party=3) vsquish post
	estimates store rep2
// fair
reg fair i.panel##i.party, robust
	margins r.panel, at(party=1) vsquish post
	estimates store ind3
reg fair i.panel##i.party, robust
	margins r.panel, at(party=2) vsquish post
	estimates store dem3
reg fair i.panel##i.party, robust
	margins r.panel, at(party=3) vsquish post
	estimates store rep3		
// trust	
reg trust i.panel##i.party, robust
	margins r.panel, at(party=1) vsquish post
	estimates store ind4
reg trust i.panel##i.party, robust
	margins r.panel, at(party=2) vsquish post
	estimates store dem4
reg trust i.panel##i.party, robust
	margins r.panel, at(party=3) vsquish post
	estimates store rep4	
			
coefplot (dem3, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
         (rep3, color(538r) ciopts(lcolor(538r) recast(rcap))) ///
		 (ind3, color(538g) ciopts(lcolor(538g) recast(rcap))), ///
		  bylabel("UNHCR Panel Is Fair") || ///
		 (dem4, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
         (rep4, color(538r) ciopts(lcolor(538r) recast(rcap))) ///
		 (ind4, color(538g) ciopts(lcolor(538g) recast(rcap))), ///
		  bylabel("UNHCR Panel Can Be Trusted") || ///
		 (dem1, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
         (rep1, color(538r) ciopts(lcolor(538r) recast(rcap))) ///
		 (ind1, color(538g) ciopts(lcolor(538g) recast(rcap))), ///
		  bylabel("Outcome Is Good for American") || ///
		 (dem2, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
         (rep2, color(538r) ciopts(lcolor(538r) recast(rcap))) ///
		 (ind2, color(538g) ciopts(lcolor(538g) recast(rcap))), ///
		  bylabel("Outcome Is Good for Refugee") vertical ///
		 yline(0) ytitle("Marginal Difference (All-White, All-Male vs. Diverse Panels") ///
		 xtitle("Racial and Gender Distribution of Panel (All-White, All-Male as Reference Group)") ///
		 xlabel(1 `""Mixed-Race" "All-Male""' 2 `""All-White" "Mixed-Gender""' ///
			    3 `""Mixed-Race" "Mixed-Gender""', ///
		 labcol(black)) scheme(plottig) ///
		 legend(order(2 "Democrats" 4 "Republicans" 6 "Independents") rows(1)) 
	  
